<template>
  <div class="goods-comment-image">
    <!-- 可点击的图片列表 -->
    <div class="list">
      <a
        href="javascript:;"
        v-for="(item,index) in imageList"
        :key="item"
        @click="curIndex = index "
        :class="{active: curIndex === index}"
      >
        <img :src="item" alt="">
      </a>
    </div>
    <!-- 当前激活图片的大图展示 -->
    <!--
      curIndex 默认为null  预览功能还未开启 没有点击图片
      点击图片的时候 curIndex 不是null 预览功能已经开启  大图盒子展示
     -->
    <div class="preview" v-if="curIndex !== null">
      <img :src="imageList[curIndex]" alt="">
      <i class="iconfont icon-close-new" @click="curIndex = null">×</i>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
export default {
  props: {
    imageList: {
      type: Array
    }
  },
  setup () {
    const curIndex = ref(null)
    return {
      curIndex
    }
  }
}
</script>

<style scoped lang="less">
.goods-comment-image {
  .list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    a {
      width: 120px;
      height: 120px;
      border:1px solid #e4e4e4;
      margin-right: 20px;
      margin-bottom: 10px;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
      &.active {
        border-color: @xtxColor;
      }
    }
  }
  .preview{
    position: relative;
    img{
      width: 100%;
    }
    i{
      position: absolute;
      right: 0;
      top: 0;
      width:30px;
      height: 30px;
      //   background-color: #ccc;
      font-size: 24px;
      text-align: center;
      line-height: 30px;
      cursor: pointer;
    }
  }
}
</style>
